<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人和人律师事务所管理系统v1.0-现金支票管理</title>

<style type="text/css" media="all">
.allow-float {
	clear: none !important;
}  /* 允许该元素浮动 */
.stop-float {
	clear: both !important;
}  /* 阻止该元素浮动 */
.float-left {
	float: left;
	padding-left: 10px
} /*浮动到左边*/
</style>

<script type="text/javascript">
	Ext.onReady(function(){
		//添加现金支票信息窗口
		var addChequeWindow;
		//添加现金支票信息form
		var addChequeForm;

		//月份数据
		var datas=[{id:'01',name:'一月份'},{id:'02',name:'二月份'},{id:'03',name:'三月份'},{id:'04',name:'四月份'},
		{id:'05',name:'五月份'},{id:'06',name:'六月份'},{id:'07',name:'七月份'},{id:'08',name:'八月份'},
		{id:'09',name:'九月份'},{id:'10',name:'十月份'},{id:'11',name:'十一月份'},{id:'12',name:'十二月份'}
		];
		//月份存储器
		var monthstore=new Ext.data.JsonStore({ data:datas,fields:["id","name"]});
		//查询框
   		 var seaChequeWinPanel = new Ext.form.FormPanel({
    		labelAlign:'right',
			title:'现金支票信息查询',
			labelSeparator :'：',//分隔符
			labelWidth : 80,//标签宽度
			bodyStyle:'padding:5',//表单边距
			frame : true,
			collapsible: true,
			height:100,
			width:window.screen.width-220,
			applyTo :'searchChequeWin',

			items:[
				new Ext.form.TextField({
					fieldLabel : '请输入年份',
					id : 'chequeYear',
					name : 'chequeYear',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.ComboBox({
					fieldLabel:'请选择月份',
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					store:monthstore,
					valueField:'id',
					displayField:'name',
					mode:'local',
					forceSelection:true,
					emptyText:'请选择月份',
					editable:false,
					triggerAction:'all',
					id:'chequeMonth',
					name:'chequeMonth'
				}),

				new Ext.Button({
					text : ' 开始查询 ',
					iconCls:'search',
					cls:'float-left',//向左浮动
					handler : submitMsg
				})
			]
		})

		//查询处理函数
		function submitMsg(){
		//获得要查询的年份与月份
		var chequeYear=Ext.getCmp("chequeYear").getValue();
		//判断是否输入了年份
		if(chequeYear==null||chequeYear=="")
		{
		Ext.Msg.alert('信息', '请输入年份再提交!');
		return;
		}
		//获得要查询的月份
		var chequeMonth=Ext.getCmp("chequeMonth").getValue();
		//重构存储器
		store = new Ext.data.JsonStore({
				url:"SearchChequeInfo.jsj?chequeYear="+chequeYear+"&chequeMonth="+chequeMonth,
				totalProperty: 'totalCount',
   				root: 'result',
				fields:["cashchequeid","cashchequetime","cashchequebrief","cashchequeperson","chequeamount","chequeapplication"]
				});
			//重新加载存储器
			store.reload({
				params:{
				start:0,
				limit:5
				}
				});
				//重新设置列显示格式
		var colModel = new Ext.grid.ColumnModel([//配置表格列
				new Ext.grid.RowNumberer({
				header : '行号',
				width : 40
				}),
				cb,
				{header: "开出日期",width: 200,  dataIndex: 'cashchequetime', sortable: true},
				{header: "摘要（支票号）", width: 200,dataIndex: 'cashchequebrief', sortable: true},
				{header: "金额",width: 200, dataIndex: 'chequeamount', sortable: true},
				{header: "经手人",width: 200, dataIndex: 'cashchequeperson', sortable: true},
				{header: "用途",width: 200, dataIndex: 'chequeapplication', sortable: true},
				]);
				//分页工具栏重新绑定存储器
				pagebar.bind(store);
				//GRID重新加载数据
				grid.reconfigure(store,colModel);
				//刷新GRID界面
				grid.getView().refresh(true);
		}

    	//存储器
		var store = new Ext.data.JsonStore({
					url:"ChequeInfoRequest.jsj",
					totalProperty: 'totalCount',
					root: 'result',
					fields:["cashchequeid","cashchequetime","cashchequebrief","cashchequeperson","chequeamount","chequeapplication"]
				});
				//加载数据
			store.load({
					params:{
					start:0,
					limit:5
					}
				});

		//根據用戶權限決定按鈕是否有效
		var buttonDisabled=true;
		<%
		if((java.lang.Integer)session.getAttribute("popedomLevel")==1){
		%>
		buttonDisabled=false;
		<%
		}
		%>



		//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '现金支票详细信息'},
			'-',
			{
			text:'增加现金支票信息',
			iconCls:'add',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			addChequeInfo();
			}
			},
			'-',
			{
			text:'修改',
			iconCls:'option',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			modifyChequeInfoFun();
			}
			}
			]);


			//增加一条现金支票记录处理函数
			function addChequeInfo(){
			//增加現金支票記錄窗口
			addChequeWindow=new Ext.Window({
						title:'增加一条现金支票记录',
						width:450,
						height:240,
						layout:'fit',
						closeAction:'hide',
						resizable:false,
						items:addChequeForm
					});
			//顯示窗口
			addChequeWindow.show();
			}

			//增加现金支票面板
		    addChequeForm=new Ext.FormPanel({
	 					labelAlign:'right',
	 					buttonAlign:'center',
	 					frame:true,
	 					labelWidth:150,
	 					defaults:{
	 					width:180,
	 							 },
				items:[
						{
						xtype:'datefield',
						fieldLabel:'时间',
						format:'Y-m-d',
						name:'chequeTime',
						allowBlank:false
						},
						{
							xtype:'textfield',
							fieldLabel:'摘要（支票号）',
							name:'chequeBrief',
							allowBlank:false
						},
						{
							xtype:'textfield',
							fieldLabel:'金额',
							name:'chequeAmount',
							allowBlank:false
						},
						{
							xtype:'textfield',
							fieldLabel:'经手人',
							name:'chequePerson',
							allowBlank:false
						},
						{
							xtype:'textfield',
							fieldLabel:'用途',
							name:'chequeApp',
							allowBlank:false
						}
					],
			buttons:[{
						text:'确认',
						handler:function(){
						//判斷用戶輸入數據是否完整有效
						if(addChequeForm.form.isValid()){
						  		addChequeForm.form.submit({
									url:'AddChequeAccount.jsj',
									success:function(form,action){
									Ext.MessageBox.alert('结果',action.result.message);
									//刷新数据
									store.load({
									params:{
									start:0,
									limit:5
									}
									});
									addChequeWindow.hide();
								},
									failure: function(form,action){
									Ext.MessageBox.alert('结果',action.result.message);
									//刷新数据
									store.load({
									params:{
									start:0,
									limit:5
									}
									});
									addChequeWindow.hide();
								},
								waitMsg:'正在保存数据，稍后...'
								});
							} else {
								Ext.Msg.alert('信息', '请填写完成再提交!');
							}
						}
						},{
						 text:'取消',
						 handler:function(){
						 addChequeWindow.hide();
						 }
		}]
	});



	     //修改现金支票面板
    	 var modifyCashChequePanel;
     	//修改现金支票窗口
     	 var modifyCashChequeWin;
     	 //修改现金支票记录
     	  function modifyChequeInfoFun(){
		 //获取要修改的一条记录
       	 var record=grid.getSelectionModel().getSelected();
       	//如果用户没有选择
       	if(!record){
       		Ext.MessageBox.alert('修改操作','请选择要修改的一项！');
       	   }else{
       		//修改现金支票窗口
       		modifyCashChequeWin=new Ext.Window({
       			layout:'fit',
       			width:500,
       			height:250,
       			closeAction:'hide',
				plain:true,
				title:'修改现金支票窗口',
				items:modifyCashChequePanel
       		});
       		//显示窗口
       		modifyCashChequeWin.show();
       		//加载原数据
       		 Ext.getCmp("mCashChequeId").setValue(record.get("cashchequeid"));
       		 Ext.getCmp("mCashChequeTime").setValue(record.get("cashchequetime"));
       		 Ext.getCmp("mCashChequeBrief").setValue(record.get("cashchequebrief"));
       		 Ext.getCmp("mCashChequePerson").setValue(record.get("cashchequeperson"));
       		 Ext.getCmp("mCashChequeAmount").setValue(record.get("chequeamount"));
       	     Ext.getCmp("mCashChequeApplication").setValue(record.get("chequeapplication"));
       	}
       }

       //修改现金支票面板
       modifyCashChequePanel=new Ext.form.FormPanel({
        labelAlign:'right',
        buttonAlign:'center',
       	collapsible:true,
       	labelwidth:100,
       	frame:true,
       	bodyStyle : 'padding:5px 5px 0',
        waitMsgTarget : true,

        defaults : {
            width : 250
        },
        defaultType : 'textfield',
        items : [
         {
         	xtype:'hidden',
            name :'mCashChequeId',
            id :'mCashChequeId'
        },
        {
            fieldLabel : '计入时间',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'mCashChequeTime',
            id :'mCashChequeTime',
            allowBlank :false
        },
        {
            fieldLabel : '摘要（支票号）',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'mCashChequeBrief',
            id :'mCashChequeBrief',
            allowBlank :false
        },
        {
            fieldLabel :'经手人',
			id :'mCashChequePerson',
			name :'mCashChequePerson',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        },
        {
            fieldLabel :'金额',
			id :'mCashChequeAmount',
			name :'mCashChequeAmount',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        },
        {
            fieldLabel :'用途',
			id :'mCashChequeApplication',
			name :'mCashChequeApplication',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        }
        ],

        buttons : [ {
            text : '保存',
            disabled : false,
            handler : function() {
                if (modifyCashChequePanel.form.isValid()) {
                    modifyCashChequePanel.form.submit( {
                        url : 'ModifyCashChequeInfo.jsj',
                        success : function(from, action) {
                        Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyCashChequeWin.hide();
                        },
                        failure : function(form, action) {
                           Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyCashChequeWin.hide();
                        },
                        waitMsg : '正在保存数据，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        }, {
            text : '取消',
            handler : function() {
                modifyCashChequeWin.hide();
            }
        }]
       })



		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});

		//创建选择模式对象
		var cb = new Ext.grid.CheckboxSelectionModel()

		//创建Grid表格组件
		var grid = new Ext.grid.GridPanel({
			renderTo : 'cheque-detail-info',//渲染到某個控件上顯示
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			trackMouseOver:true, //鼠标特效
			loadMask: true,    //是否显示正在加载
			store : store,	//存儲器
			height : 320,
			width : window.screen.width-220,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "开出日期",width: 200,  dataIndex: 'cashchequetime', sortable: true},
				{header: "摘要（支票号）", width: 200,dataIndex: 'cashchequebrief', sortable: true},
				{header: "金额",width: 200, dataIndex: 'chequeamount', sortable: true},
				{header: "经手人",width: 200, dataIndex: 'cashchequeperson', sortable: true},
				{header: "用途",width: 200, dataIndex: 'chequeapplication', sortable: true},
				]
			});
});

</script>
</head>
<body>
<table>
	<tr>
		<td>
		<div id='searchChequeWin' style="margin: 8px 8px 4px 8px"></div>
		</td>
	</tr>
</table>
<div id='cheque-detail-info' style="margin: 4px 8px 8px 8px"></div>


</body>
</html>